<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="root"></div>

    <script src="./lib/react.js"></script>
    <script src="./lib/react_dom.js"></script>
    <script src="./lib/babel.js"></script>
    <script type="text/babel">
      const root = ReactDOM.createRoot(document.querySelector("#root"));
      let message = "hello world";

      function btnClick() {
        // 修改数据
        message = "hello react";
        // 重新渲染, react重新渲染需要手动调用render
        rootRender();
      }

      rootRender();
      function rootRender() {
        root.render(
          <div>
            <h2>{message}</h2>
            <button onClick={btnClick}>修改文本</button>
          </div>
        );
      }
    </script>
  </body>
</html>
